package tech.kpretty.lock;

import java.util.concurrent.TimeUnit;

class Phone_ {
    public static synchronized void sendEmail() {
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "-->发送邮件");
    }

    public synchronized void sendMSN() {
        System.out.println(Thread.currentThread().getName() + "-->发送短信");
    }

    public void sendQQ() {
        System.out.println(Thread.currentThread().getName() + "-->发送QQ");
    }
}

public class EightLockDemo {
    public static void main(String[] args) throws InterruptedException {
        Phone_ phone = new Phone_();
        Phone_ phone1 = new Phone_();
        new Thread(() -> phone.sendEmail(), "A").start();
        TimeUnit.MILLISECONDS.sleep(100);
        new Thread(() -> phone1.sendMSN(), "B").start();
    }
}
